﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CommunitySystem.PageView
{
    public partial class ZhiJiControl : UserControl
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        EmpbasicService.ZhiJiModel RoleModel = new EmpbasicService.ZhiJiModel();
        public ZhiJiControl()
        {
            InitializeComponent();
            LoadData();
        }

        void LoadData()
        {
            Client.GetZhiJiModelCompleted += new EventHandler<EmpbasicService.GetZhiJiModelCompletedEventArgs>(Client_GetZhiJiModelCompleted);
            Client.GetZhiJiModelAsync(0);
        }

        void Client_GetZhiJiModelCompleted(object sender, EmpbasicService.GetZhiJiModelCompletedEventArgs e)
        {
            DGRole.ItemsSource = null;
            DGRole.ItemsSource = e.Result;
        }

        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            ZhiJiWindow RMWindow = new ZhiJiWindow(0, true);
            RMWindow.Closed += new EventHandler(RMWindow_Closed);
            RMWindow.Show();
        }

        void RMWindow_Closed(object sender, EventArgs e)
        {
            LoadData();
        }

        private void EditData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as EmpbasicService.ZhiJiModel;

            if (seljw != null)
            {
                ZhiJiWindow RMWindow = new ZhiJiWindow(Convert.ToInt32(seljw.ID), false);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的职务层次！"); 
        }
    }
}
